<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>欢迎光临--- <span>未登录</span> </h1>
     <a href="./login.html">登录</a> <a href="javascript:;" class="look">查看订单</a>
     <button>退出登录</button>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.2/jquery.js"></script>
<script>
    // 获取本地token
    let token = localStorage.getItem("LOGIN_TOKEN");
    if(token){
        $("span").text("已登录")
        $("a").css("display","none")
        $("button").css("display","block"); 
        $(".look").css("display","block")
    }else{
        $("span").text("未登录") 
        $("a").css("display","block")
        $("button").css("display","none");
        $(".look").css("display","none")
    }
    $("button").click(()=>{
        // 删除本地token 退出登录
        localStorage.removeItem('LOGIN_TOKEN')
        location.reload();
    })

    // 查  看订单
    $(".look").click(()=>{
        $.ajax({
            url:"/get/oreder",
            method:"get",
            // 设置请求头 添加授权字段
            headers:{
                // 自定义授权字段 ，只要需要授权的接口都必须携带授权字段
                authorations:token,
            },
            success(res){
                console.log(res)
            }
        })
    })
</script>
</html>